package com.rc.saas.mini.config;

/**
 * Created by Sven on 2021/06/28
 */

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

@Configuration
@EnableAsync
public class SpringAsyncConfig {
    @Bean
    public Executor notifyStationsStatusTaskExecutor() {
        //@Async默认使用Bean Name为executor的线程池,也可以根据Bean Name指定特定线程池
        ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
        pool.setCorePoolSize(5); //线程池活跃的线程数
        pool.setMaxPoolSize(10); //线程池最大活跃的线程数
        pool.setWaitForTasksToCompleteOnShutdown(true);
        pool.setThreadNamePrefix("lalala");
        return pool;
    }
}
